/******************************************************************************
 * The contents of this file are subject to the   JDI License  Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Initial Developer of the Original Code is 陈慧然. Portions created by 
 * 陈慧然 are Copyright 陈慧然.
 * All Rights Reserved.
 *
 *              Contact john_holen@163.com for licensing alternatives.
 *
 *****************************************************************************/


package org.peony.client.web.components.form;

import org.peony.client.web.components.WebComponents;
import org.peony.exceptions.RenderException;
import org.peony.standard.ui.SIComponent;
import org.peony.tools.StringUtil;

/**
 *  
 *
 *  @author     陈慧然
 *  @version    Id: SelectItem.java, v 0.000 2008-5-5 上午11:11:17 陈慧然 Exp
 */
public class SelectOption extends WebComponents{
	private boolean isDefault = false;
	private SIComponent value;
	private String dataValue;
	public boolean isDefault() {
		return isDefault;
	}
	public void setDefault(boolean isDefault) {
		this.isDefault = isDefault;
	}
	public SIComponent getValue() {
		return value;
	}
	public void setValue(SIComponent value) {
		this.value = value;
	}
	public String getDataValue() {
		return dataValue;
	}
	public void setDataValue(String dataValue) {
		this.dataValue = dataValue;
	}
	@Override
	public String toStandardString() throws RenderException {
		if(StringUtil.isEmpty(getId()))
			throw new RenderException("Option (A Component) Can NOT has no id!");
		StringBuffer sb = new StringBuffer();
		sb.append("<option")
			.append(" id= \"").append(getId()).append("\"")
			.append(" value=\"").append(getDataValue()).append("\"")
			.append(StringUtil.isNotEmpty(getUIClass())?" class=\"" + getUIClass()+"\"":empty)
			.append(isDefault()?" selected==\"selected\"":empty)
			.append(">")
			.append(getValue()==null?empty:getValue().toStandardString()).append("</option>");
		return sb.toString();
	}
}
